package com.example.smartcitymovie.dao;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteDatabase;

import com.example.smartcitymovie.entity.User;

import cn.hutool.crypto.digest.MD5;

@Database(entities = {User.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
    public abstract Userdao userDao();

    @Override
    public void init(@NonNull DatabaseConfiguration configuration) {
        configuration.callbacks.add(roomDatabaseCallback);
        super.init(configuration);
    }

    private static RoomDatabase.Callback roomDatabaseCallback = new RoomDatabase.Callback() {
        @Override
        public void onCreate(@NonNull SupportSQLiteDatabase db) {
            MD5 md5 = MD5.create();
            String password = md5.digestHex("123456");

            db.execSQL(String.format("insert into user(id,user_name,nick_name,password,email,phonenumber,sex,avatar) values(1,'user','张三','%s','123@qq.com','12123212345',1,'https://pic.netbian.com/uploads/allimg/230922/164533-1695372333fb00.jpg')",password));
            super.onCreate(db);
        }
    };
}
